$('.yzm').click(()=>{
    var phone=$('#phone').val().trim();
    var phoneReg=/^1(3[0-9]|5[189]|8[6789])[0-9]{8}$/;
    if(!phone) {
        layer.msg("请输入手机号", {time: 1500})
    }else if(!phoneReg.test(phone)){
        layer.msg("请输入正确的手机号码", {time: 1500})
    }else{
        //获取验证码
        var time=60;
        var timer=setInterval(()=>{
            time--;
            $('.yzm').html(time+'秒');
            if(time<=0){
                clearInterval(timer);
                $('.yzm').html('再次获取');
            }
        },1000);
    }
})
$('#cpwd').blur(()=>{
    var npwd=$('#npwd').val().trim();
    var cpwd=$('#cpwd').val().trim();
    if(npwd!==cpwd){
        layer.msg("两次密码不一致",{time:1500});
    }
})
$(".btn").click(()=>{
    var phone=$('#phone').val().trim();
    var code=$('#code').val().trim();
    var upwd=$('#upwd').val().trim();
    var npwd=$('#npwd').val().trim();
    var cpwd=$('#cpwd').val().trim();
    if(!phone){layer.msg("请输入手机号",{time:1500})}
    else if(!code){layer.msg("请输入验证码",{time:1500})}
    else if(!upwd){layer.msg("请输入密码",{time:1500})}
    else if(!npwd){layer.msg("请输入新密码",{time:1500})}
    else if(!cpwd){layer.msg("请输入确认密码",{time:1500})}
    else if(npwd!==cpwd){
        layer.msg("两次密码不一致",{time:1500});
    }
    else{
        $.ajax({
            type:'post',
            url:'',
            data:{phone:phone,code:code,upwd:upwd,npwd:npwd},
            success:function (data){
                layer.msg("修改成功",{time:1500});
                location.href='login.html';
            },
            error:function () {

            }

        })
    }
})
